package luweiteng.demoForLogin.vo.resp;


import lombok.Data;
import luweiteng.demoForLogin.constant.ErrorCode;
import luweiteng.demoForLogin.exception.DocUserException;

import java.io.Serializable;

@Data
public class BaseResp<T> implements Serializable {
    private static final long serialVersionUID = 8955649811596771957L;
    private String msg;
    private Integer status;
    private T data;


    public static <T> BaseResp<T> fail() {
        BaseResp resp = new BaseResp();
        resp.status = -1;
        resp.msg = "服务器开小差";
        return resp;
    }

    public static <T> BaseResp<T> fail(Integer code ,String msg) {
        BaseResp resp = new BaseResp();
        resp.setStatus(code);
        resp.setMsg(msg);
        return resp;
    }

    public static <T> BaseResp<T> fail(ErrorCode errorCode) {
        BaseResp resp = new BaseResp();
        resp.status = errorCode.getErrorCode();
        resp.msg = errorCode.getErrorMsg();
        return resp;
    }

    public static <T> BaseResp<T> success() {
        BaseResp resp = new BaseResp();
        resp.msg = "success";
        resp.status = 200;
        return resp;
    }

    public static <T> BaseResp<T> success(T data) {
        BaseResp resp = new BaseResp();
        resp.msg = "success";
        resp.status = 200;
        resp.data = data;
        return resp;
    }
}
